﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Drawing ;

using DotSpatial.Topology;
using DotSpatial.Serialization;

 
using DotSpatial.Data;

using DotSpatial.Symbology;
using DotSpatial.Symbology.Forms;

using System.Drawing.Design ;
using System.Windows.Forms ;
using System.Windows.Forms.Design ;

using System.ComponentModel ;
using System.ComponentModel.Design ;
using System.IO ;
using System.Data;



namespace HaGisPack
{



    [Serializable ]
    public class FEPointLayer : FShapeLayer
    {

        public FEPointLayer(string id ):base(id)
        {
            this.m_Type = FeatureType.Point;

            //(this._PointSymbol as PointSymbolizer).ScaleMode = ScaleMode.Simple;

            //(this._PointSymbol as PointSymbolizer).Symbols[0].SymbolType=
            (this._PointSymbol as PointSymbolizer).SetFillColor(Color.Black);
            (this._PointSymbol as PointSymbolizer).SetSize(new Size2D(5, 5));
            //(this._PointSymbol as PointSymbolizer).SetOutline(Color.Red, 1);


            this.Configure();

        }

        protected override void BuildLayer()
        {
            base.BuildLayer();
            //this._PointSymbol = (this.ILayer as IFeatureLayer).Symbolizer;
            (this.ILayer as IFeatureLayer).Symbolizer = this._PointSymbol as PointSymbolizer;
        }


        //点的常用属性，点的样式等。作为资源嵌入的也可以计算在内

        #region "属性封装"
               
       
        //刘加
        [NonSerialized]
        private object _PointSymbol = new PointSymbolizer();

        [Editor(typeof(PointSymbolEditor), typeof(UITypeEditor))]  
        [Category("基体信息"), DisplayName("点基本信息设置")]
        public object PointSymbol
        {
            get 
            {               
                return this._PointSymbol;
            }
            set
            {
                this._PointSymbol = value;
                this.OnSetSymbol();

            }
        }

        protected void OnSetSymbol()
        {
            if (this.BRunning)
                (this.ILayer as IFeatureLayer).Symbolizer = (PointSymbolizer)_PointSymbol;
        }

        //-------------------------------------------------------------------------------------//

        [NonSerialized]
        private object _SelectSymbol = new PointSymbolizer();

        [Editor(typeof(PointSymbolEditor), typeof(UITypeEditor))]  
        [Category("基体信息"), DisplayName("所选点基本信息设置")]
        public object SelectionSymbol
        {
            get { return this._SelectSymbol; }
            set
            {
                this._SelectSymbol = value;
                this.OnSetSelectSymbol();

            }
        }

        protected void OnSetSelectSymbol()
        {
            if (this.BRunning)
                (this.ILayer as IFeatureLayer).SelectionSymbolizer = (PointSymbolizer)this._SelectSymbol;        
        }



        //现在又一个疑问，是调用系统默认的属性对话框呢，还是自己写，包括树，以及属性编辑。


        #endregion



        # region protected methods

        public override void SaveEntity()
        {
            base.SaveEntity();


            XmlSerializer xs = new XmlSerializer();
            //string xmlLayer = xs.Serialize(this.ILayer);
            //File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "Layer.xml", xmlLayer);

            string xmlSymbol = xs.Serialize(this._PointSymbol);
            File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "Symbol.xml", xmlSymbol);

            string xmlSelectSymbol = xs.Serialize(this._SelectSymbol);
            File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "SelectSymbol.xml", xmlSelectSymbol);

            //string xmlLabel = xs.Serialize(this._LabelLayer);
            //File.WriteAllText(this.m_ParenLManager.layerPath + this.Id + "Label.xml", xmlLabel);

        }


        public override void LoadEntity()
        {
            base.LoadEntity();

            XmlDeserializer xd = new XmlDeserializer();



            //string xmlLayer = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "Layer.xml");
            //xd.Deserialize(this.ILayer, xmlLayer);
            //this.ILayer = xd.Deserialize<DotSpatial.Controls.IMapLayer>(xmlLayer);

            string xmlSymbol = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "Symbol.xml");
            this._PointSymbol = xd.Deserialize<PointSymbolizer>(xmlSymbol);

            string xmlSelectSymbol = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "SelectSymbol.xml");
            this._SelectSymbol = xd.Deserialize<PointSymbolizer>(xmlSelectSymbol);

            //string xmlLabel = File.ReadAllText(this.m_ParenLManager.layerPath + this.Id + "Label.xml");
            //xd.Deserialize(this._LabelLayer, xmlSymbol);

        }

        # endregion





    }
}
